﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace MPMovieCatalog.Settings.Sections
{
    public class PropertyElementCollection : ConfigurationElementCollection
    {
        public override
            ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return
                    ConfigurationElementCollectionType.AddRemoveClearMap;
            }
        }

        public PropertyElement this[int index]
        {
            get
            {
                return base.BaseGet(index) as PropertyElement;
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }

        protected
            override System.Configuration.ConfigurationElement CreateNewElement()
        {
            return new PropertyElement();
        }

        protected override object GetElementKey(
            System.Configuration.ConfigurationElement element)
        {
            return ((PropertyElement)element).Name;
        }

        public void Add(PropertyElement element)
        {
            BaseAdd(element);
        }
    }
}
